﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using IGolovkine.Core.Diagnostics;

namespace IGolovkine.ShoutCastRipper.Filters
{
    public class ContentTitlePatternFilter : IContentTitleFilter
    {
        private readonly IEnumerable<string> _streamTitlePatterns;
        public ContentTitlePatternFilter(IEnumerable<string> streamTitlePatterns)
        {
            Debug.NotDefault(() => streamTitlePatterns);
            _streamTitlePatterns = streamTitlePatterns;
        }

        public string Name
        {
            get { return "Pattern Filter"; }
        }

        public ContentTitleFilterResult Process(string streamTitle)
        {
            foreach (string mask in _streamTitlePatterns)
            {
                if (Regex.IsMatch(streamTitle, mask, RegexOptions.IgnoreCase) == true)
                {
                    return ContentTitleFilterResult.AcceptedResult();
                }
            }

            return ContentTitleFilterResult.RejectedResult("Content title '{0}' doesn't match any of the stream title patterns", streamTitle);
        }
    }
}
